﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Team6_Algorithms.Sorting
{ 
    /// <summary>
    /// Made by Pascal Schotman && Dylan Snel
    /// Class solely used to hold the quicksort methods
    /// </summary>
    public class QuickSort
    {
        /// <summary>
        /// Sorts the given array using quicksort.
        /// </summary>
        public static void Sort(int[] items)
        {
            quicksort(items, 0, items.Length - 1);
        }

        private static void quicksort(int[] items, int left, int right)
        {

            int i, j;
            int x, y;

            i = left; j = right;
            x = items[(left + right) / 2];


            do
            {
                while ((items[i] < x) && (i < right)) i++;
                while ((x < items[j]) && (j > left)) j--;

                if (i <= j)
                {
                    y = items[i];
                    items[i] = items[j];
                    items[j] = y;
                    i++; j--;
                }
            } while (i <= j);

            if (left < j) quicksort(items, left, j);
            if (i < right) quicksort(items, i, right);
        }
    }
}
